package com.study.sxc.service;

import com.study.sxc.Dao.IUserDao;
import com.study.sxc.Entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class userService {

    private static final Logger log = LoggerFactory.getLogger(userService.class);

    @Resource
    IUserDao userDao;

    public List<User> getUsers(List<Integer> ids) {
        log.info("查询用户列表，参数：{}", ids);
        List<User> users = userDao.getUsers(ids);
        log.info("DAO层返回数据：{}", users);
        if(users == null || users.isEmpty()) {
            return new ArrayList<>();
        }
        return users;
    }

    public int addUser(User user) {
        log.info("新增用户，参数：{}", user);
        int result = userDao.addUser(user);
        log.info("新增用户结果：{}", result);
        return result;
    }

    public int updateUser(User user) {
        log.info("更新用户，参数：{}", user);
        int result = userDao.updateUser(user);
        log.info("更新用户结果：{}", result);
        return result;
    }

    public void deleteUser(Integer id) {
        log.info("删除用户，参数：{}", id);
        userDao.deleteUser(id);
        log.info("删除用户成功");
    }

    public User getUserById(Integer id) {
        return userDao.getUserById(id);
    }

    /**
     * 查询所有用户
     */
    public java.util.List<com.study.sxc.Entity.User> getAllUsers() {
        return userDao.getAllUsers();
    }
} 